package App.Repository;

import App.Entity.Person;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by yu on 2017/7/18.
 */
@Repository
public interface PersonRepository extends CrudRepository<Person,Long>
{
    public Person findFirstByAuthId(Long auth_id);

    @Query("select id from Person person where person.authId=:authId")
    public int getPersonId(@Param("authId") long authId);

    @Modifying
    @Query("update Person person set person.img=:img where person.authId=:authId")
    public int updateImgByAuthId(@Param("img")String img,@Param("authId")long authId);

    @Query("select img from Person person where person.authId=:authId")
    public String getPersonImgByAuthId(@Param("authId") long authId);

    @Query("select username from Person person where person.authId=:authId")
    public String getPersonNameByAuthId(@Param(("authId")) long authId);

    public List<Person> findPeopleByAuthIdIn(List<Long>ids);

    public List<Person> findByUsernameLike(String like);

    public List<Person> findByCellphoneLike(String like);
}
